package com.salt.modules.sys.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.salt.common.persistence.TreeEntity;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 菜单Entity
 * @author salt
 * @version 2016-05-15
 */
@JsonIgnoreProperties(value={"hibernateLazyInitializer","handler"})
public class Menu extends TreeEntity<Menu> {

	private static final long serialVersionUID = 1L;
	private String href; 	// 链接
	private String target; 	// 目标（ mainFrame、_blank、_self、_parent、_top）
	private String icon; 	// 图标
	private String isShow; 	// 是否在菜单中显示（1：显示；0：不显示）
	private String type; //按钮类型
	private String permission; // 权限标识
	private List<DataRule> dataRuleList;
	private String backgroundType;
	private String menuRoute;

	// --------- 前端改版用 start -------
	private String iconBackColor; // 图标背景颜色
	private String iconColor; // 图标颜色
	private String titleColor; // 标题颜色
	private String dockId; // Mac版页面Dock条Id
	private String detail; // 详情
	// ***** 不做持久化 start *****
	private String progressBarSuccessful = "";  // 进度条成功状态
	private int progressBarValue = 0;  // 进度条数值
	private int downloadStatus = 0;   // 下载状态
	private int isDownload = 0;  // 是否已下载（0：否；1：是）
	private int isDownloadAuth = 0; // 是否有下载权限（0：否；1：是）
	private int progressDisplay = 0; // 进度显示
	private int rightMenuVisible = 0; // 右键菜单栏显示
	private String imageIcon; // 图片路径
	private String menuType;
	// ***** 不做持久化 end *****
	// --------- 前端改版用 end -------


	private String userId;
	private String tenant; // 租户标识
	private String client; // 客户端（1：手机端；2：PC端）
	private List<String> tenantIds; // 租户标识ID的集合 不做持久化

	public Menu(){
		super();
		this.sort = 30;
		this.isShow = "1";
		this.type="1";
	}

	public Menu(String tenant, List<String> tenantIds, String client) {
		super();
		this.sort = 30;
		this.isShow = "1";
		this.type="1";
		this.tenant = tenant;
		this.tenantIds = tenantIds;
		this.client = client;
	}

	public Menu(String id){
		super(id);
	}

	public Menu getParent() {
		return parent;
	}

	public void setParent(Menu parent) {
		this.parent = parent;
	}

	@Length(min=1, max=2000)
	public String getParentIds() {
		return parentIds;
	}

	public void setParentIds(String parentIds) {
		this.parentIds = parentIds;
	}

	@Length(min=1, max=100)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Length(min=0, max=2000)
	public String getHref() {
		return href;
	}

	public void setHref(String href) {
		this.href = href;
	}

	@Length(min=0, max=20)
	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	@Length(min=0, max=100)
	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	@NotNull
	public Integer getSort() {
		return sort;
	}

	public void setSort(Integer sort) {
		this.sort = sort;
	}

	@Length(min=1, max=1)
	public String getIsShow() {
		return isShow;
	}

	public void setIsShow(String isShow) {
		this.isShow = isShow;
	}

	@Length(min=0, max=200)
	public String getPermission() {
		return permission;
	}

	public void setPermission(String permission) {
		this.permission = permission;
	}

	public String getParentId() {
		return parent != null && parent.getId() != null ? parent.getId() : "0";
	}

	@JsonIgnore
	public static void sortList(List<Menu> list, List<Menu> sourcelist, String parentId, boolean cascade){
		for (int i=0; i<sourcelist.size(); i++){
			Menu e = sourcelist.get(i);
			if (e.getParent()!=null && e.getParent().getId()!=null
					&& e.getParent().getId().equals(parentId)){
				list.add(e);
				if (cascade){
					// 判断是否还有子节点, 有则继续获取子节点
					for (int j=0; j<sourcelist.size(); j++){
						Menu child = sourcelist.get(j);
						if (child.getParent()!=null && child.getParent().getId()!=null
								&& child.getParent().getId().equals(e.getId())){
							sortList(list, sourcelist, e.getId(), true);
							break;
						}
					}
				}
			}
		}
	}

	@JsonIgnore
	public static String getRootId(){
		return "1";
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	@Override
	public String toString() {
		return name;
	}

	public List<DataRule> getDataRuleList() {
		return dataRuleList;
	}

	public void setDataRuleList(List<DataRule> dataRuleList) {
		this.dataRuleList = dataRuleList;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getBackgroundType() {
		return backgroundType;
	}

	public void setBackgroundType(String backgroundType) {
		this.backgroundType = backgroundType;
	}

	public String getMenuRoute() {
		return menuRoute;
	}

	public void setMenuRoute(String menuRoute) {
		this.menuRoute = menuRoute;
	}

	public String getIconBackColor() {
		return iconBackColor;
	}

	public void setIconBackColor(String iconBackColor) {
		this.iconBackColor = iconBackColor;
	}

	public String getIconColor() {
		return iconColor;
	}

	public void setIconColor(String iconColor) {
		this.iconColor = iconColor;
	}

	public String getDockId() {
		return dockId;
	}

	public void setDockId(String dockId) {
		this.dockId = dockId;
	}

	public String getTitleColor() {
		return titleColor;
	}

	public void setTitleColor(String titleColor) {
		this.titleColor = titleColor;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public String getProgressBarSuccessful() {
		return progressBarSuccessful;
	}

	public void setProgressBarSuccessful(String progressBarSuccessful) {
		this.progressBarSuccessful = progressBarSuccessful;
	}

	public int getProgressBarValue() {
		return progressBarValue;
	}

	public void setProgressBarValue(int progressBarValue) {
		this.progressBarValue = progressBarValue;
	}

	public int getDownloadStatus() {
		return downloadStatus;
	}

	public void setDownloadStatus(int downloadStatus) {
		this.downloadStatus = downloadStatus;
	}

	public int getIsDownload() {
		return isDownload;
	}

	public void setIsDownload(int isDownload) {
		this.isDownload = isDownload;
	}

	public int getProgressDisplay() {
		return progressDisplay;
	}

	public void setProgressDisplay(int progressDisplay) {
		this.progressDisplay = progressDisplay;
	}

	public int getIsDownloadAuth() {
		return isDownloadAuth;
	}

	public void setIsDownloadAuth(int isDownloadAuth) {
		this.isDownloadAuth = isDownloadAuth;
	}

	public int getRightMenuVisible() {
		return rightMenuVisible;
	}

	public void setRightMenuVisible(int rightMenuVisible) {
		this.rightMenuVisible = rightMenuVisible;
	}

	public String getTenant() {
		return tenant;
	}

	public void setTenant(String tenant) {
		this.tenant = tenant;
	}

	public List<String> getTenantIds() {
		return tenantIds;
	}

	public void setTenantIds(List<String> tenantIds) {
		this.tenantIds = tenantIds;
	}

	public String getClient() {
		return client;
	}

	public void setClient(String client) {
		this.client = client;
	}


	public String getImageIcon() {
		return imageIcon;
	}

	public void setImageIcon(String imageIcon) {
		this.imageIcon = imageIcon;
	}

	public String getMenuType() {
		return menuType;
	}

	public void setMenuType(String menuType) {
		this.menuType = menuType;
	}

}
